package Nisha.collections;

import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Queue;
import java.util.Set;
import java.util.TreeSet;

class SetObjects implements Comparable
{
	int id;
	String name;
	public SetObjects(int id, String name)
	{
		this.id = id;
		this.name = name;
	}
	
	@Override
	public String toString() {

		return this.id + " "+this.name;
	}
	
	@Override
	public int hashCode() {
		
		return ((Integer)(this.id)).hashCode()+ this.name.hashCode();
	}
	
	@Override
	public boolean equals(Object paramObject) {
		SetObjects temp = (SetObjects)paramObject;
		if((this.id==(temp.id))&&(this.name.equals(temp.name))&&(this.getClass().isInstance(paramObject)))
				{
			return true;
				}
		else
			return false;
}

	@Override
	public int compareTo(Object o) {
		SetObjects temp = (SetObjects)o;
		if(this.id>temp.id)
		return 1;
		else if(this.id==temp.id)
			return this.name.compareTo(temp.name);
		else 
			return 0;
	}
}
public class SetDemo {

	public static void main(String[] args) {
		Set<SetObjects> hashSetExample = new HashSet<SetObjects>();
		Set<SetObjects> treeSetExample = new TreeSet<SetObjects>();
		Set<SetObjects> linkedHashSetExample = new LinkedHashSet<SetObjects>();
		 
		SetObjects SetObjects4 = new SetObjects(03,"Mradul");
		SetObjects SetObjects1 = new SetObjects(01,"Nisha");
		SetObjects SetObjects2 = new SetObjects(02,"Zayal");
		SetObjects SetObjects3 = new SetObjects(02,"Payal");
		
		hashSetExample.add(SetObjects1);
		hashSetExample.add(SetObjects2);
		hashSetExample.add(SetObjects3);
		hashSetExample.add(SetObjects4);
		System.out.println(hashSetExample);
		
		treeSetExample.add(SetObjects1);
		treeSetExample.add(SetObjects2);
		treeSetExample.add(SetObjects3);
		treeSetExample.add(SetObjects4);
		System.out.println(treeSetExample);
		
		linkedHashSetExample.add(SetObjects1);
		linkedHashSetExample.add(SetObjects2);
		linkedHashSetExample.add(SetObjects3);
		linkedHashSetExample.add(SetObjects4);
   
		
		System.out.println(linkedHashSetExample);
		
	

	}

}
